<div class="portlet light bordered">
	<div class="portlet-title">
		<div class="caption font-dark">
			<i class="fa fa-cog font-dark"></i> 
			<span class="caption-subject bold">账房 > 单据管理 > 收款单 > 新增</span>
		</div>
	</div>
	<div class="portlet-body form">
		<form role="form" action="/orderReceipt/add" class="form-horizontal" method="post" enctype="multipart/form-data">
			<div class="modal-body">
				<div class="form-group">
					<label class="control-label col-md-3">*公司名称：</label>
					<div class="col-md-7">
						<select name="companyId" id="companyChange"  class="form-control companyId" required>
							<option value="">--请选择--</option>
							#foreach($item in $companyList)
								<option value="$!item.id">$!item.name</option>
								<!-- companyId  -->
							#end
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label col-md-3">*付款类型：</label>
					<div class="col-md-7">
						<select name="payType" id="payType" class="form-control" required>
						   <option value="DELIVER" selected>运费</option>
							<option value="CREDIT" >信用还款</option>
							<!-- <option value="ORDER" selected>订单付款</option> -->
							<!-- <option value="DELIVER">运费</option> -->
							<option value="OTHER">其它费用</option>
						</select>
					</div>
				</div>
				<!-- <div class="form-group orderId">
					<label class="control-label col-md-3">*付款订单：</label>
					<div class="col-md-7">
						<select name="orderId" id="orderId" class="form-control" required>
							<option value="">--请选择--</option>
						</select>
					</div>
				</div> -->
				<div class="form-group">
					<label class="control-label col-md-3">*付款金额：</label>
					<div class="col-md-7">
						<input type="number" class="form-control"  id="cashFee" name="cashFee" min="0.01" max="999999999.99" required>
					</div>
				</div>
				
				<div class="form-group orderUserName">
					<label class="control-label col-md-3">*付款会员：</label>
					<div class="col-md-7">
						<select name="nickname" id="nickname" class="form-control" required>
							<!-- <option value="">--请选择--</option> -->
							<!-- #foreach($item1 in $userInfoList)
								<option value="$!item1.nickname">$!item1.nickname</option>
							#end -->
						</select>
					</div>
				</div>
				
				
				
				<div class="form-group">
					<label class="control-label col-md-3">*付款方式：</label>
					<label class="control-label">
						<input type="radio" name="payway" value="PAY_ONLINE" checked> 在线支付  &nbsp;&nbsp;
	                    <input type="radio" name="payway" value="PAY_OFFLINE"> 线下支付
					</label>
				</div>
				<div class="form-group settleWay">
					<label class="control-label col-md-3">*网银付款方式：</label>
					<label class="control-label">
						<input type="radio" name="settleWay" value="ALIPAY" checked> 支付宝支付  &nbsp;&nbsp;
						<input type="radio" name="settleWay" value="WECHAT"> 微信支付  &nbsp;&nbsp;
						<input type="radio" name="settleWay" value="ONLINE_BANK"> 企业网银
					</label>
				</div>
				<div class="form-group cashWay">
					<label class="control-label col-md-3">*结算方式：</label>
					<div class="col-md-7">
						<select name="cashWay" id="cashWay" class="form-control" required>
							<option value="CASH" selected>现金</option>
							<option value="BANK_TRANSFER">银行转账</option>
						</select>
					</div>
				</div>
				<div class="form-group payBankId">
					<label class="control-label col-md-3">*汇款银行账户：</label>
					<div class="col-md-7">
						<select name="payBankId" id="payBankId" class="form-control" required>
						   
						</select>
						<span id="maxError"    style="color: red;" hidden="true">请先添加银行用户</span>
					</div>
				</div>
				<div class="form-group reachBankId">
					<label class="control-label col-md-3">*收款银行账户：</label>
					<div class="col-md-7">
						<select name="reachBankId" id="reachBankId" class="form-control" required>
						 <option value="">请选择</option>
						#foreach($bankMap in $!sysParam.getSysListMap())
							<option value="$!bankMap.id" >$!bankMap.bankName  账号：$!bankMap.cardBank</option>
					   #end
							
						</select>
					</div>
				</div>
				<div class="form-group payDate">
					<label class="control-label col-md-3">*支付时间：</label>
					<div class="col-md-7">
						<input class="form-control common-time-datepicker" type="text" id="payDate" name="payDate" id="payDate" required readonly>
					</div>
				</div>
				<div class="form-group reachDate">
					<label class="control-label col-md-3">*到账时间：</label>
					<div class="col-md-7">
						<input class="form-control common-time-datepicker" type="text" id="reachDate" name="reachDate" id="reachDate" required readonly>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label col-md-3">备注信息：</label>
					<div class="col-md-7">
						<textarea class="medium m-warp form-control" rows="4" cols="70" id="note" name="note"></textarea>
					</div>
				</div>
				<div class="form-group attachImage">
					<label class="control-label col-md-3">附件信息：</label>
					<div class="col-md-7">
                         <div class="fileinput fileinput-new" data-provides="fileinput">
							<div class="fileinput-new thumbnail" style="width: 100px; height: 75px;">
								<img src="/assets/images/upload.png" alt="上传图片">
							</div>
							<div class="fileinput-preview fileinput-exists thumbnail"style="max-width: 600px; max-height: 600px;"></div>
							<div style="display: inline-block;">
								<span class="btn default btn-file"> 
									<span class="fileinput-new"> 浏览 </span> 
									<span class="fileinput-exists">更改 </span> 
									<input type="file" id="file" name="file" accept="image/jpg,image/gif,image/bmp,image/jpeg,image/png" >
								</span>
								<a href="javascript:;" class="btn red fileinput-exists" data-dismiss="fileinput"> 删除 </a>
							</div>
						</div>
					</div>
					
				</div>
			</div>
			<div class="form-actions right">
                 <a href="javascript:;" thref="/orderReceipt/list" class="btn green ajax-file"><i class="fa fa-check"></i>确认付款</a>
                 <a href="javascript:;" data-dismiss="modal" class="btn btn-outline grey-salsa">返回</a>
            </div>
		</form>
	</div>
</div>
<script src="/assets/scripts/views-file-edit.js" type="text/javascript"></script>
<script src="/assets/scripts/views-date.js" type="text/javascript"></script>
<script type="text/javascript">
ComponentsSelect2.initWithSearch();

$("form").on("change",".companyId",function(){
	debugger;
	var companyId = $(this).find("option:selected").val();
	var formData = new FormData();
    formData.append("companyId", companyId);
	$.ajax({
		url: "/orderReceipt/orderList",
		type: "POST",
		data: formData,
		contentType: false,
		processData: false,
		dataType: "json",
		success: function(res) {
			var options = '<option value="">--请选择--</option>';
			for (var key in res) {
				options = options + "<option value="+ key +">"+ res[key] + "</option>"; 
			}
			$("#orderId").html(options);
		}
	})
}) 


$("form").on("change",".companyId",function(){
	var companyId = $(this).find("option:selected").val();
	var formData = new FormData();
    formData.append("companyId", companyId);
	$.ajax({
		url: "/orderReceipt/autodate",
		type: "POST",
		data: formData,
		contentType: false,
		processData: false,
		dataType: "json",
		success: function(res) {
			var options = '<option value="">--请选择--</option>';
			for(var key=0;key<res.length;key++){
				 if(res[key].nickname!=null&&res[key].nickname!=""){
				    options = options + "<option value="+ res[key].nickname +">"+res[key].nickname+ "</option>"; 
				}else{ 
				    options = options + "<option value="+ res[key].realname +">"+res[key].realname+ "</option>"; 
				}
				$("#nickname").html(options); 
			}
			
			/* for (var key=0; key<res.lengrh) {
				
				options = options + "<option value="+ key +">"+res.nickname+ "</option>"; 
				
			} */
			//$("#nickname").html(options); 
		},
		 error:function(){
			 alert("错误"); 
		   }
	
	   
	})
});

 $(".companyId").on("change",function(){
	$("#select2-nickname-container").empty();
	$("#select2-payBankId-container").empty(); 
}); 
$("form").on("change",".companyId",function(){
	//$("#payBankId option :gt(1)").val(""); 

	$("#payBankId").html(null); 
	var companyId = $(this).find("option:selected").val();
	
	var formData = new FormData();
    formData.append("companyId", companyId);
    
	$.ajax({
		url: "/orderReceipt/BandList",
		type: "POST",
		data: formData,
		contentType: false,
		processData: false,
		dataType: "json",
		success: function(backData) {
			
			
			if(backData.length<=0){
			     $("#maxError").removeAttr("hidden");
				var options = '<option value="" style="color: red;">--请先增银行账户--</option>';
				
				return;
			}else{
				   $("#maxError").attr("hidden","hidden");
				var options = '<option value="">--请选择--</option>';
				for(var key=0;key<backData.length;key++){
						    options = options + "<option value="+ backData[key].id +">"+backData[key].bankName+" 账号:"+backData[key].bankNum+"</option>"; 
				}
		 }
			$("#payBankId").html(options); 
			
		},
		 error:function(){
			 alert("错误"); 
		   }
	
	   
	})
}) 
 //ajaax验证企业名下的银行
/* $("#companyChange").on('change',function(){
	var companyId=$(this).val();
	$.ajax({
		type:'post',
		url:'/orderReceipt/autodate',
		data:{"companyId":companyId},
		dataType: "json",
		success:function(data){
			
		}
	})
}); 
 */



/* $.ajax({  
    type: 'post',  
    url: xxx.action',  
    dataType: 'text',  
    success: function(data){              
        var dataObj=eval("("+data+")");     
        for(var i=0;i<dataObj.length;i++){      
            alert(dataObj[i].id+" "+dataObj[i].name);     
        }  
                      
        var jsonObj=eval("("+data+")");  
        $.each(jsonObj, function (i, item) {  
            alert(item.id + ","  + item.name);  
        });  
    },  
    error: function(text) {}  
});  

 */
 //display 隐藏元素位不占位
//disabled 表单元素不被提交
$("form").on("change","#payType",function(){
	var payType = $(this).find("option:selected").val();
	if(payType=="ORDER"){
		$(".orderId").show();
		$("#orderId").removeAttr("disabled");
	}else{
		$("#orderId").attr("disabled","disabled");
		$(".orderId").hide();
	}
})

$("form").on("click","input[name='payway']",function(){
	var payway = $("input[name='payway']:checked").val();
	if(payway=="PAY_ONLINE"){
		$(".settleWay").show();
		$("input[name='settleWay']").removeAttr("disabled");
		
		$("#cashWay").attr("disabled","disabled");
		$(".cashWay").hide();
		$("#payBankId").attr("disabled","disabled");
		$(".payBankId").hide();
		$("#reachBankId").attr("disabled","disabled");
		$(".reachBankId").hide();
		$("#payDate").attr("disabled","disabled");
		$(".payDate").hide();
		$("#reachDate").attr("disabled","disabled");
		$(".reachDate").hide();
		$("#file").attr("disabled","disabled");
		$(".attachImage").hide();
	}else{
		$("input[name='settleWay']").attr("disabled","disabled");
		$(".settleWay").hide();
		
		$(".cashWay").show();
		$("#cashWay").removeAttr("disabled");
		$(".payBankId").show();
		$("#payBankId").removeAttr("disabled");
		$(".reachBankId").show();
		$("#reachBankId").removeAttr("disabled");
		$(".payDate").show();
		$("#payDate").removeAttr("disabled");
		$(".reachDate").show();
		$("#reachDate").removeAttr("disabled");
		$(".attachImage").show();
		$("#file").removeAttr("disabled");
	}
})

$(function(){
	$("#cashWay").attr("disabled","disabled");
	$(".cashWay").hide();
	$("#payBankId").attr("disabled","disabled");
	$(".payBankId").hide();
	$("#reachBankId").attr("disabled","disabled");
	$(".reachBankId").hide();
	$("#payDate").attr("disabled","disabled");
	$(".payDate").hide();
	$("#reachDate").attr("disabled","disabled");
	$(".reachDate").hide();
	$("#file").attr("disabled","disabled");
	$(".attachImage").hide();
})

</script>